package com.bawei.monthdemo2207a.month02.mine

import android.widget.ImageView
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Badge
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import coil.load
import com.bawei.monthdemo2207a.R
import com.stx.xhb.xbanner.XBanner

/**
 * 作者：赵亮
 * 时间：2024/12/31 11:32
 * 功能：
 */
@Composable
fun MinePage() {

    var list = listOf(R.drawable.banner, R.drawable.banner, R.drawable.banner)

    Column {

        // 轮播图
        AndroidView(modifier = Modifier
            .fillMaxWidth()
            .height(200.dp), factory = {
            val xBanner = XBanner(it)
            xBanner.setData(list, null)
            xBanner.setmAdapter { banner, view, position -> (view as ImageView).load(list[position]) }
            xBanner
        })

        // 应用更新提示
        Card (modifier = Modifier
            .fillMaxWidth()
            .padding(horizontal = 10.dp)){
            Column (modifier = Modifier
                .fillMaxWidth()
                .padding(10.dp)){
                Text(text = "应用管理")
                Row (modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceAround){
                    listOf("下载安装", "更新", "卸载").forEachIndexed { index, s ->
                        Column(horizontalAlignment = Alignment.CenterHorizontally) {
                            Box {
                                Image(
                                    modifier = Modifier.size(40.dp),
                                    painter = painterResource(id = R.drawable.logo),
                                    contentDescription = null
                                )
                                if (index == 1) {
                                    Badge (modifier = Modifier.align(Alignment.TopEnd).offset(x = 13.dp, y=-13.dp)){
                                        Text(text = "3")
                                    }
                                }
                            }
                            Text(text = s)
                        }
                    }
                }
            }
        }
    }
}

@Preview
@Composable
fun MinePagePreview() {
    MinePage()
}

